//
//  Mytools.m
//  AllPass
//
//  Created by apple on 2021/11/1.
//

#import "Mytools.h"

@implementation Mytools
+ (NSString *)documentsDirectory {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [paths objectAtIndex:0];
}
+(void)NeedResetNoViewWithView:(UIView*)tab andArr:(NSArray*)arr{
    if (arr.count>0) {
        [tab dismissNoView];
    }else{
        [tab dismissNoView];
        [tab showNoView:@"暂无数据" image:Image(@"empty_icon") certer:CGPointZero];
    }
}
+(void)NeedResetNoViewWithView:(UIView*)tab andArr:(NSArray*)arr point:(CGPoint)poi{
    if (arr.count>0) {
        [tab dismissNoView];
    }else{
        [tab dismissNoView];
        [tab showNoView:@"暂无数据" image:Image(@"empty_icon") certer:poi];
    }
}
+(void)NeedResetNoViewWithView:(UIView*)tab msg:(NSString*)msg andArr:(NSArray*)arr image:(UIImage*)img{
    if (arr.count>0) {
        [tab dismissNoView];
    }else{
        [tab dismissNoView];
        [tab showNoView:msg.length?msg:@"暂无数据" image:img?:Image(@"empty_icon") certer:CGPointZero];
    }
}


+ (NSArray *)matchString:(NSString *)string toRegexString:(NSString *)regexStr{
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionCaseInsensitive error:nil];
    NSArray * matches = [regex matchesInString:string options:0 range:NSMakeRange(0, [string length])];
    NSMutableArray *array = [NSMutableArray array];
    for (NSTextCheckingResult *match in matches) {
        for (int i = 0; i < [match numberOfRanges]; i++) {
            //以正则中的(),划分成不同的匹配部分
            NSString *component = [string substringWithRange:[match rangeAtIndex:i]];
            [array addObject:component];
        }
    }
    return array;
}
//字符串转日期
+(NSDate*)dateStrToDate:(NSString *)dateStr{
    NSTimeZone *zone = [NSTimeZone localTimeZone];
    NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setTimeZone:zone];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date =[dateFormat dateFromString:dateStr];
    NSInteger interval = [zone secondsFromGMTForDate: date];
    NSDate *date2 = [date  dateByAddingTimeInterval: interval];
//    NSDate *date2 = [date dateByAddingTimeInterval:8 * 60 * 60];
    return date2;
}
+(NSDate*)dateStrToDate:(NSString *)dateStr withFormat:(NSString*)format{
    NSTimeZone *zone = [NSTimeZone localTimeZone];
    NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setTimeZone:zone];
    [dateFormat setDateFormat:format];
    NSDate *date =[dateFormat dateFromString:dateStr];
    NSInteger interval = [zone secondsFromGMTForDate: date];
    NSDate *date2 = [date  dateByAddingTimeInterval: interval];
    return date2;
}
+(NSString *)dateToDateStr:(NSDate*)date{
    NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    [dateFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
    NSString *currentDateStr = [dateFormat stringFromDate:date];
    return currentDateStr;
}
@end
